package lines.gameengine.strategy;

import lines.gameengine.FieldPoint;
import lines.gameengine.IField;

import java.util.Collection;
import java.util.HashSet;

/**
 * @author vpotapenko
 */
public class DefaultBallStrategy extends AbstractBallStrategy {

    private final LinesFinder finder;

    public DefaultBallStrategy(IField field, int value) {
        super(value, field);

        finder = new LinesFinder(field);
    }

    @Override
    public boolean apply(FieldPoint point) {
        Collection<FieldPoint> lines = new HashSet<FieldPoint>();
        finder.find(point, lines);

        final boolean canApply = !lines.isEmpty();
        if (canApply) getField().clearCells(lines);

        return canApply;
    }
}
